"""
企业微信告警模块

curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' \
   -H 'Content-Type: application/json' \
   -d '
   {
        "msgtype": "text",
        "text": {
            "content": "hello world"
        }
   }'
"""
from requests import post  # conda install requests
from json import dumps

URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='
HEADERS = {'content-type': 'application/json'}
NAME = '您的大名'


def report(text):
    data = dumps({
        'msgtype': 'text',
        'text': {
            'content': text,
            'mentioned_list': [NAME],
        }
    })
    print(post(url=URL, headers=HEADERS, data=data))


def alert(text, exception=None):
    report(text)
    raise Exception(exception)


if __name__ == '__main__':
    report('测试报告')
    alert('测试告警')

